<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:with="title='Blogs',active='article'">
<header th:replace="admin/fragments/header::headerFragment(${title},${active})"></header>

<body class="fixed-left">
    <div id="wrapper">
        <div th:replace="admin/fragments/header::header-body"></div>
        <div class="content-page">
            <div class="content">
                <div class="container">
                    <div class="row">
                        <div class="col-sm-12">
                            <h4 class="page-title">Articles</h4>
                        </div>
                        <div class="col-md-12">
                            <table class="table table-striped table-bordered">
                                <thead>
                                    <tr>
                                        <th width="25%">Title</th>
                                        <th width="8%">Tag</th>
                                        <th width="20%">Time</th>
                                        <th>Read</th>
                                        <th>Category</th>
                                        <th width="8%">Status</th>
                                        <th>Opration</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <th:block th:each="post : ${articles.list}">
                                        <tr th:cid="${post.cid}">
                                            <td>
                                                <a th:href="@{'/admin/article/'+${post.cid}}"
                                                    th:text="${post.title}"></a>
                                            </td>
                                            <td>
                                                <th:block th:if="${post.type == 'post'}">
                                                    <span class="label label-success">Blog</span>
                                                </th:block>
                                            </td>
                                            <td>
                                                <th:block
                                                    th:text="${commons.fmtdate(post.created, 'yyyy-MM-dd HH:mm:ss')}" />
                                            </td>
                                            <td>
                                                <th:block th:text="${post.hits}" />
                                            </td>
                                            <td>
                                                <th:block th:text="${post.categories}" />
                                            </td>
                                            <td>
                                                <th:block th:if="${post.status == 'publish'}">
                                                    <span class="label label-success">Published</span>
                                                </th:block>
                                                <th:block th:if="${post.status == 'draft'}">
                                                    <span class="label label-default">Draft</span>
                                                </th:block>
                                            </td>
                                            <td>
                                                <a th:href="@{'/admin/article/'+${post.cid}}"
                                                    class="btn btn-primary btn-sm waves-effect waves-light m-b-5">
                                                    <i class="fa fa-edit"></i> <span>Edit</span>
                                                </a>
                                                <a href="javascript:void(0)" th:onclick="'delPost('+${post.cid}+');'"
                                                    class="btn btn-danger btn-sm waves-effect waves-light m-b-5">
                                                    <i class="fa fa-trash-o"></i> <span>Delete</span>
                                                </a>
                                                <a class="btn btn-warning btn-sm waves-effect waves-light m-b-5"
                                                    th:href="${post.type=='post' ? commons.blogPermalink(post.cid) : commons.photoPermalink(post.cid)}"
                                                    target="_blank">
                                                    <i class="fa fa-rocket"></i> <span>Preview</span>
                                                </a>
                                            </td>
                                        </tr>
                                    </th:block>

                                </tbody>
                            </table>
                            <div th:replace="comm/macros :: pageAdminNav(${articles})"></div>
                        </div>
                    </div>
                    <div th:replace="admin/fragments/footer :: footer-content"></div>
                </div>
            </div>
        </div>
    </div>
    <div th:replace="admin/fragments/footer :: footer"></div>
    <script type="text/javascript">
        /*<![CDATA[*/
        var tale = new $.tale();
        function delPost(cid) {
            tale.alertConfirm({
                title: 'Sure to delete?',
                then: function () {
                    tale.post({
                        url: '/admin/article/delete',
                        data: { cid: cid },
                        success: function (result) {
                            if (result && result.code == 'success') {
                                tale.alertOkAndReload('Successful!');
                            } else {
                                tale.alertError(result.msg || 'Failed!');
                            }
                        }
                    });
                }
            });
        }
    /*]]>*/
    </script>
</body>

</html>